<template>
  <el-card>
    <div slot="header" class="clearfix">
      <span>公会贡献</span>
    </div>
    <el-form ref="contributionForm" :model="contribution" label-width="100px">
      <el-form-item label="玩家ID">
        <el-input v-model="contribution.playerId" placeholder="请输入玩家ID"></el-input>
      </el-form-item>
      <el-form-item label="贡献值">
        <el-input v-model="contribution.value" placeholder="请输入贡献值"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="recordContribution">记录贡献</el-button>
      </el-form-item>
    </el-form>
    <el-table :data="contributions" style="width: 100%; margin-top: 20px;">
      <el-table-column prop="id" label="贡献ID" width="100"></el-table-column>
      <el-table-column prop="playerId" label="玩家ID"></el-table-column>
      <el-table-column prop="value" label="贡献值"></el-table-column>
      <el-table-column prop="recordTime" label="记录时间"></el-table-column>
      <el-table-column label="操作" width="150">
        <template #default="scope">
          <el-button @click="updateContribution(scope.row)" type="primary" size="small">编辑</el-button>
        </template>
      </el-table-column>
    </el-table>
  </el-card>
</template>

<script setup>
import { ref, onMounted } from 'vue';
import { recordGuildContribution, getContributionsByGuildId, updateGuildContribution } from '@/utils/requests.js';

const contribution = ref({
  playerId: '',
  value: null,
  recordTime: ''
});

const contributions = ref([]);

const loadContributions = async () => {
  const response = await getContributionsByGuildId(1); // 假设公会ID为1
  contributions.value = response.data;
};

onMounted(() => {
  loadContributions();
});

const recordContribution = async () => {
  await recordGuildContribution(contribution.value);
  loadContributions();
};

const updateContribution = (contrib) => {
  // 实现更新贡献逻辑
};
</script>